//
//  MBCommodityDetailTipsCell.swift
//  iPhone
//
//  Created by Toj on 8/11/22.
//

import UIKit

class MBCommodityDetailTipsCell: UICollectionViewCell {
    
    var model: MBCommodityDetailTipsModel? { didSet {
         guard let commodity = model else { return }
        
        tipsLabel.text = commodity.user_notification
        tipsView.isHidden = commodity.user_notification.isEmpty
        introduceLabel.attributedText = commodity.introduceAttributed
        
        introduceLabel.snp.remakeConstraints { make in
            make.bottom.equalTo(contentView)
            make.height.equalTo(commodity.introduceHeight)
            make.left.right.equalTo(tipsView)
        }
    } }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupMakeAddSubviews()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        setupMakeLayoutSubviews()
    }
    
    // 提示
    private lazy var tipsLabel: UILabel = {
        let view = UILabel()
        view.numberOfLines = 0
        view.textColor = "#99773C".to_color
        view.font = UIFont.systemFont(ofSize: 12.f_scale)
        return view
    }()
    
    // 提示背景
    private lazy var tipsView: UIView = {
        let view = UIView()
        view.st_cornerRadius = 4
        view.backgroundColor = "#FFFAEE".to_color
        view.st_border(color: "#FFF6D6".to_color)
        return view
    }()
    
    // 介绍
    private lazy var introduceLabel: UILabel = {
        let view = UILabel()
        view.numberOfLines = 0
        view.textColor = "#999999".to_color
        return view
    }()
}

// MARK: - 初始化
extension MBCommodityDetailTipsCell {
    
    private func setupMakeAddSubviews() {
        
        contentView.addSubview(tipsView)
        contentView.addSubview(tipsLabel)
        contentView.addSubview(introduceLabel)
    }
    
    private func setupMakeLayoutSubviews() {
        
        tipsLabel.snp.makeConstraints { make in
            make.top.equalTo(8)
            make.left.equalTo(8)
            make.right.equalTo(snp.right).offset(-8.ui_scale)
        }
        
        tipsView.snp.makeConstraints { make in
            make.left.top.right.equalTo(contentView)
            make.bottom.equalTo(tipsLabel.snp.bottom).offset(8.ui_scale)
        }
        
        introduceLabel.snp.makeConstraints { make in
            make.bottom.equalTo(contentView)
            make.left.right.equalTo(tipsView)
        }
    }
}
